def IsPrime(N):
    for index in range(2, int(N**0.5)+1):
        if N%index == 0:
            return False
    return True

def FindingNearestPrimeNum(Num):
    BiggerNearestPrimeNumber = 0
    SmallerNearestPrimeNumber = 0
    
    for NumIdx in range(Num, Num*10000, +1):
        if NumIdx > Num and IsPrime(NumIdx):
            BiggerNearestPrimeNumber = NumIdx
            break
    for NumIdx in range(Num, 2, -1):
        if NumIdx < Num and IsPrime(NumIdx):
            SmallerNearestPrimeNumber = NumIdx
            break
    if BiggerNearestPrimeNumber - Num < Num - SmallerNearestPrimeNumber:
        print(BiggerNearestPrimeNumber)
    else:
        print(SmallerNearestPrimeNumber)

Digits = {
    'zero':'0',
    'one':'1',
    'two':'2',
    'three':'3',
    'four':'4',
    'five':'5',
    'six':'6',
    'seven':'7',
    'eight':'8',
    'nine':'9',
}

StringNum = input()
Number = ''

for index in StringNum.split(' '):
    if index in Digits:
        Number += Digits[index]
    else:
        print('WRONG INPUT')
        exit()

FindingNearestPrimeNum(int(Number))
